<?php

namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Company;

class ProcessCompany implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $fileName = 'company_names.txt';

        $filePath = resource_path('data/' . $fileName);

        if (file_exists($filePath)) {
            $file = file($filePath);

            for ($i=166801; $i < count($file); $i++) { 
                $company = new Company;
                $company->name = $file[$i];
                $company->save();

            }
        }

        echo "Finish process company" . PHP_EOL;
    }
}
